#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Yield/BondHelper.h>
#pragma unmanaged 
#include <ql\termstructures\yield\bondhelpers.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Instruments::Bonds;
using namespace Cephei::QL::Instruments;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Yield {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IFixedRateBondHelper
	public ref class CFixedRateBondHelper  : 
            public CBondHelper,
            public Cephei::QL::Termstructures::Yield::IFixedRateBondHelper
	{
	protected: 
		boost::shared_ptr<QuantLib::FixedRateBondHelper>* _ppFixedRateBondHelper;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FixedRateBondHelper>* _phFixedRateBondHelper;
#endif
		Object^ _FixedRateBondHelperOwner;     // reference to object that manages the storage for this object
	internal:
		CFixedRateBondHelper (Cephei::QL::IQuote^ cleanPrice, UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConv, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate);
        CFixedRateBondHelper (boost::shared_ptr<QuantLib::FixedRateBondHelper>& childNative, Object^ owner);
        CFixedRateBondHelper (QuantLib::FixedRateBondHelper& childNative, Object^ owner);
        CFixedRateBondHelper (CFixedRateBondHelper^ copy);
        CFixedRateBondHelper (PLATFORM::Type^ t);
#ifdef STRUCT
        CFixedRateBondHelper (QuantLib::FixedRateBondHelper childNative);
#endif       
#ifdef HANDLE
		CFixedRateBondHelper (QuantLib::Handle<QuantLib::FixedRateBondHelper>& childNative, Object^ owner);
		CFixedRateBondHelper (QuantLib::Handle<QuantLib::FixedRateBondHelper> childNative);
#endif
		virtual ~CFixedRateBondHelper ();
		!CFixedRateBondHelper ();

	internal:
		QuantLib::FixedRateBondHelper& GetReference ();
		boost::shared_ptr<QuantLib::FixedRateBondHelper>& GetShared ();
		QuantLib::FixedRateBondHelper* GetPointer ();
        void SetFixedRateBondHelper (boost::shared_ptr<QuantLib::FixedRateBondHelper> native)
        {
            if (_ppFixedRateBondHelper != NULL)
                delete _ppFixedRateBondHelper;
            _ppFixedRateBondHelper = new boost::shared_ptr<QuantLib::FixedRateBondHelper> (native);
            SetBondHelper (boost::dynamic_pointer_cast<QuantLib::BondHelper> (*_ppFixedRateBondHelper));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FixedRateBondHelper>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Instruments::Bonds::IFixedRateBond^ FixedRateBond 
        {
		    virtual Cephei::QL::Instruments::Bonds::IFixedRateBond^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IFixedRateBondHelper Vector interface
	ref class CFixedRateBondHelperVector sealed : 
							    public Core::INativeVector<IFixedRateBondHelper^>,
							    public Core::INativeVector<Core::Generic::ICoCell<IFixedRateBondHelper^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::FixedRateBondHelper>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::FixedRateBondHelper>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::FixedRateBondHelper>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CFixedRateBondHelperVector ();
#ifdef STRUCT
		CFixedRateBondHelperVector (std::vector<QuantLib::FixedRateBondHelper>& vec, Object^ owner);
		CFixedRateBondHelperVector (std::vector<QuantLib::FixedRateBondHelper> vec);
#endif       
		CFixedRateBondHelperVector (std::vector<boost::shared_ptr<QuantLib::FixedRateBondHelper>>& vec, Object^ owner);
#ifdef HANDLE
		CFixedRateBondHelperVector (std::vector<QuantLib::Handle<QuantLib::FixedRateBondHelper>>& vec, Object^ owner);
#endif
		virtual ~CFixedRateBondHelperVector ();
		!CFixedRateBondHelperVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IFixedRateBondHelper^ default[int] 
		{
			virtual IFixedRateBondHelper^ get (int index) = Core::INativeVector<IFixedRateBondHelper^>::default::get;
			virtual void set (int index, IFixedRateBondHelper^ value) = Core::INativeVector<IFixedRateBondHelper^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Core::Generic::ICoCell<Cephei::QL::Termstructures::Yield::IFixedRateBondHelper^>^ CItem[int] 
		{
			virtual Core::Generic::ICoCell<IFixedRateBondHelper^>^ get (int index) = Core::INativeVector<Core::Generic::ICoCell<IFixedRateBondHelper^>^>::default::get;
			virtual void set (int index, Core::Generic::ICoCell<IFixedRateBondHelper^>^ value) = Core::INativeVector<Core::Generic::ICoCell<IFixedRateBondHelper^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::FixedRateBondHelper>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::FixedRateBondHelper>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::FixedRateBondHelper>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Termstructures::Yield::IFixedRateBondHelper^>::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IFixedRateBondHelper::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IFixedRateBondHelper_Factory::typeid)]
	public ref class CFixedRateBondHelper_Factory sealed : public IFixedRateBondHelper_Factory
	{
	public:
        virtual IFixedRateBondHelper^ Create (Cephei::QL::IQuote^ cleanPrice, UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConv, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate);
        /* <summary> Create a hybrid Vector of IFixedRateBondHelper, with event notification of changes </summary> */
        virtual Cephei::Core::IVector<IFixedRateBondHelper^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IFixedRateBondHelper, with event notification of changes </summary> */
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IFixedRateBondHelper^>^>^>^ CreateCellVector();
        virtual Cephei::Core::IVector<IFixedRateBondHelper^>^ CreateVector(PLATFORM::Collections::Generic::IEnumerable<IFixedRateBondHelper^>^ source);
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IFixedRateBondHelper^>^>^>^ CreateCellVector(PLATFORM::Collections::Generic::IEnumerable<Core::Generic::ICoCell<IFixedRateBondHelper^>^>^ source);
		virtual Core::INativeVector<Cephei::QL::Termstructures::Yield::IFixedRateBondHelper^>^ CreateNativeVector ()
		{
			return REFNEW CFixedRateBondHelperVector ();
		}

        virtual Core::INativeMatrix<Cephei::QL::Termstructures::Yield::IFixedRateBondHelper^>^ CreateNativeMatrix ()
		{
			return nullptr;
		}

        virtual Core::INativeCube<Cephei::QL::Termstructures::Yield::IFixedRateBondHelper^>^ CreateNativeCube ()
		{
			return nullptr;
		}
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Yield */}
